<?php
session_start();
include("connect.php");

$file="DailyExpense";
$table="daily-expense";
$result = mysql_query("SHOW COLUMNS FROM `".$table."`");
$i = 0;
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$csv_output .= $row['Field'].", ";
$i++;
}
}
$csv_output .= "\n";
if($_GET[userid]=='ALLUSER'){
	$sql="SELECT * FROM `".$table."`";
}else{
	$sql="SELECT * FROM `".$table."` WHERE userid='$_GET[userid]'  AND date >= '$_GET[stDate] 00:00:00' AND date <='$_GET[endDate] 23:59:59'";
}
$values = mysql_query($sql);
while ($rowr = mysql_fetch_row($values)) {
for ($j=0;$j<$i;$j++) {
$csv_output .= $rowr[$j].", ";
}
$csv_output .= "\n";
}

$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
print $csv_output;
exit;
?>
